home *** CD-ROM | disk | FTP | other *** search
/ Emulator Universe CD / emulatoruniversecd1998.iso / CPC / Utils / CpcFile System / CPCFS.H < prev    next >
Encoding:
C/C++ Source or Header  |  1996-02-08  |  10.9 KB  |  446 lines

  1.  
  2. /*                <<<<Last Modified: Thu Feb 08 15:07:30 1996>>>>
  3. ------------------------------------------------------------------------------
  4.  
  5.         =====
  6.         CPCfs  --  c p c f s . h    Variable, Structures, Prototypes
  7.         =====
  8.  
  9.     Version 0.85                    (c) February '96 by Derik van Zuetphen
  10. ------------------------------------------------------------------------------
  11. */
  12.  
  13. #ifndef CPCFS_H_INCLUDED
  14. #define CPCFS_H_INCLUDED
  15.  
  16. #include <limits.h>
  17. #include <setjmp.h>
  18. #include <stdio.h>
  19. #include <stdlib.h>
  20. #include <stdarg.h>
  21. #include <signal.h>
  22. #include <time.h>
  23. #include "match.h"
  24.  
  25.  
  26.  
  27. /****** Configure here! (or in Makefile) ******/
  28.  
  29. /* One out of the constants LINUX, HPUX or DOS must be set to 1.
  30. This is normally done in the Makefile, in the project file, or with the
  31. Options menu. */
  32.  
  33. #ifndef DOS
  34. #define DOS        0
  35. #endif
  36. #ifndef LINUX
  37. #define LINUX        0
  38. #endif
  39. #ifndef HPUX
  40. #define HPUX        0
  41. #endif
  42. #ifndef SUNOS
  43. #define SUNOS        0
  44. #endif
  45.  
  46.  
  47. #ifndef USE_READLINE
  48. #define USE_READLINE    1    /* either GNU "readline" or ACTlib17 "inputs" */
  49. #endif
  50.  
  51. /****** End of configuration ******/
  52.  
  53. #define MAJORVERSION    0
  54. #define MINORVERSION    85
  55. #define PATCHLEVEL    0
  56. #define STAMP        __DATE__ ## " " ## __TIME__
  57. extern char stamp[];
  58.  
  59.  
  60. /****** Operating System ******/
  61.  
  62. #define SYSV    LINUX | HPUX
  63. #define BSD    SUNOS
  64. #define UNIX    SYSV | BSD
  65. #if UNIX
  66. #include "unix.h"
  67. #elif DOS
  68. #include "dos.h"
  69. #endif
  70.  
  71.  
  72.  
  73.  
  74. typedef unsigned char    uchar;
  75. /* <ushort> defined in types.h, must be in INTEL byte-order! (low, high) */
  76. #if DOS
  77. typedef unsigned short ushort;
  78. #endif
  79.  
  80. typedef char bool;
  81. #define TRUE    1
  82. #define FALSE    0
  83.  
  84.  
  85.  
  86. /***********
  87.   Variables
  88.  ***********/
  89.  
  90. /****** CPC Filesystem ******/
  91. extern int    BLKNR_SIZE;
  92. extern int    BLKNR;
  93.  
  94. typedef enum {    SYSTEMFORMAT=0x41,
  95.         DATAFORMAT=0xC1,
  96.         IBMFORMAT=0x01,
  97.         VORTEXFORMAT=0x80    /* A flag, the sector offset is 01 too*/
  98. } Format_ID;
  99.  
  100.  
  101. #define RECORDSIZE    128    /* 1/8 kByte, constant for CP/M */
  102. #define EXTENTSIZE    16384    /* 16 kByte, constant for CP/M */
  103. #define CPM_EOF        26    /* Ctrl-Z */
  104.  
  105. extern    unsigned char filler;    /* copied from track header */
  106.  
  107. extern    char    full_imagename[65];    /* full pathname, ... */
  108. extern    char    *imagename;        /* ... only name portion, and ... */
  109. extern    int    imagefile;        /* ... handle of imagefile */
  110.  
  111. extern    int    cur_user;
  112. extern    int    cur_format;
  113.  
  114. extern    uchar    *track;        /* 0x100 header + track data */
  115.  
  116. extern uchar    *block_buffer;    /* 1024 or more bytes for one block */
  117.  
  118. extern    uchar    *blk_alloc;    /* Block-Allocation-Table, points to entry, */
  119.                 /* FF = free block */
  120. extern    int    allocated_blks;
  121. extern    int    free_blks;
  122. extern    int    total_blks;    /* = allocated_blks + free_blks */
  123. extern    float    percentage;    /* of allocated blocks */
  124.  
  125.  
  126.  
  127. /****** User Interface *****/
  128. #define    CONFIGNAME    "cpcfs.cfg"
  129. #define HELPFILE    "cpcfs.hlp"
  130. #define INPUTLEN    256
  131. extern    int    nbof_args;
  132. extern    char    *arg[INPUTLEN];
  133. extern    char    prompt[INPUTLEN];
  134. extern    int    pagelen, lineno;
  135. extern    bool    Break_Wish;
  136. extern    jmp_buf break_entry;
  137. extern    bool    Interactive;
  138. extern    char    installpath[];
  139. extern    int    mode;        /* Mode for GET-commands */
  140. #define M_TEXT    1
  141. #define M_BIN    2
  142. #define M_AUTO    3
  143.  
  144. extern    bool    force;
  145. extern int    Verb;
  146.  
  147.  
  148. /****** Utility Macros ******/
  149. /* Answer a plural suffix, if nr is not 1 */
  150. #define plural(nr)    ((nr)==1?"":"s")    
  151. #define plural_y(nr)    ((nr)==1?"y":"ies")
  152. #define atoxi(CP)    (int)strtol((CP),NULL,0)
  153.             /* same as atoi, but recognizes 0x and 0 prefixes */
  154.  
  155. #ifndef max
  156. #define max(A,B)    ((A)>=(B)?(A):(B))
  157. #endif
  158. #ifndef min
  159. #define min(A,B)    ((A)<=(B)?(A):(B))
  160. #endif
  161.  
  162.  
  163. /****** Bitmasks for attributes and dir command */
  164. #define DIR_DOUBLE    0x0    /* \                */
  165. #define DIR_WIDE    0x1    /*  \ bit 0 and 1 => 4 choices    */
  166. #define DIR_AMSHEAD    0x2    /*  /                */
  167. #define DIR_LONG    0x3    /* /                */
  168. #define DIR_SORT    0x4    /*    bit 2 => 1 choice        */
  169.  
  170. #define ATTR_1        0x400
  171. #define ATTR_2        0x200
  172. #define ATTR_3        0x100
  173. #define ATTR_4        0x080
  174. #define ATTR_5        0x040
  175. #define ATTR_6        0x020
  176. #define ATTR_7        0x010
  177. #define ATTR_8        0x008
  178. #define ATTR_R        0x004
  179. #define ATTR_S        0x002
  180. #define ATTR_A        0x001
  181.  
  182.  
  183. /************
  184.   Structures
  185.  ************/
  186.  
  187. struct d_header {    /* disk header of size 0x100 */
  188.     uchar    tag[0x30];
  189.         /*00-21    MV - CPC ... */
  190.         /*22-2F    unused (0) */
  191.     uchar    nbof_tracks;
  192.         /*30    number of tracks (40) */
  193.     uchar    nbof_heads;
  194.         /*31    number of heads (1) 2 not yet supported by cpcemu */
  195.     short    tracksize;    /* short must be 16bit integer */
  196.         /*32-33    tracksize (including 0x100 bytes header)
  197.             9 sectors * 0x200 bytes each + header = 0x1300 */
  198.     uchar    unused[0xcc];
  199.         /*34-FF    unused (0)*/
  200. };
  201.  
  202. extern struct d_header disk_header;
  203.  
  204.  
  205.  
  206. struct s_info {        /* sector info, used in track header */
  207. /*Sector-Information (for each sector):*/
  208.     uchar    track;
  209.         /*18+i    tracknumber    \                */
  210.     uchar    head;
  211.         /*19+i    headnumber     | Sector-ID-Information    */
  212.     uchar    sector;
  213.         /*1A+i    sectornumber     |                */
  214.     uchar    BPS;
  215.         /*1B+i    BPS              /                */
  216.     uchar    status1;
  217.         /*1C+i    status 1 errorcode (0)*/
  218.     uchar    status2;
  219.         /*1D+i    status 2 errorcode (0)*/
  220.     uchar    unused[2];
  221.         /*1E+i,1F+i unused (0)*/
  222. } ;
  223.  
  224. struct t_header  {    /* track header of size 0x100 */
  225.     uchar    tag[0x10];
  226.         /*00-0C    Track-Info\r\n*/
  227.         /*0D-0F    unused (0)*/
  228.     uchar    track;
  229.         /*10    tracknumber (0 to number-of-tracks - 1)*/
  230.     uchar    head;
  231.         /*11    headnumber (0)*/
  232.     uchar    unused[2];
  233.         /*12-13    unused (0)*/
  234.         /*Format-Track-Parameter:*/
  235.     uchar    BPS;
  236.         /*14    BPS (bytes per sector) (2 for 0x200 Bytes)*/
  237.     uchar    SPT;
  238.         /*15    SPT (sectors per track) (9, max. 18 possible)*/
  239.     uchar    GAP3;
  240.         /*16    GAP#3 Format (gap for formatting: 0x4E)*/
  241.     uchar    filler;
  242.         /*17    Filling-Byte (filler for formatting: 0xE5)*/
  243.     struct s_info sector[29];
  244. } ;
  245.  
  246.  
  247. /****** Directory ******/
  248.  
  249. typedef struct {
  250.     uchar    user;        /* actually a byte */
  251.     uchar    root[8];    /* padded with space */
  252.     uchar    ext[3];        /* ditto         */
  253.     uchar    name[13];    /* <root 8>+"."+<ext 3>+"\0" (for globbing) */
  254.     uchar    rec;        /* size in 128 Byte records */
  255.  
  256.     int    attr;        /* bit array of size 11 (87654321rsa) */
  257.     int    blk[16];    /* 16 or 8 indices of 1 or 2 byte */
  258.     uchar    extent;        /* aka sorting criterion for dir entires */
  259.  
  260. /* only stored to write it back */
  261.     uchar    unused[2];    /* used for internal CP/M purposes */
  262.  
  263. /* organisational */
  264.     bool    first;        /* this entry is first */
  265.     long    size;        /* length in Bytes, only set if <first> */
  266.     int    next;        /* next entry for this file, -1 if last */
  267. } DirEntry;
  268.  
  269. extern DirEntry *directory;
  270.  
  271.  
  272.  
  273. /****** Disk Parameter Block ******/
  274.  
  275. typedef struct {
  276. /* extended DPB info, needed for format, in DPB_store */
  277.     uchar  ID;  /* Identifier */
  278.     ushort SEC1;/* 1. SECtor number (0, >1, >41h, >C1h) */
  279.     ushort SECS;/* number of sectors per track (8, >9) */
  280.     ushort TRKS;/* number of tracks per side (>40, 80) */
  281.     ushort HDS; /* number of heads per disk (>1, 2) */    
  282.     ushort BPS; /* Bytes Per Sector (128, 256, >512, 1024) */
  283.     
  284. /* original Disk Parameter Block (> marks CPC defaults) */
  285.     ushort SPT; /* records Per Track (18, 20, 30, 32, 34, >36, 40) */
  286.     uchar  BSH; /* Block SHift ...      2^BSH = BLM+1 = Rec/Block */
  287.     uchar  BLM; /* BLock Mask (>3/7, 4/15) */
  288.     uchar  EXM; /* EXtent Mask (0, 1)   Number of Extents/Entry - 1 */
  289.     ushort DSM; /* max. blocknumber = number of blocks - 1 */
  290.     ushort DRM; /* DiRectory size - 1 (31, >63, 127) */
  291.     uchar  AL0; /* \ DRM in binary (80h/0, >C0h/0, F0h/0) */
  292.     uchar  AL1; /* / (1 bit=1 block, 11000000/00000000 = 2 blocks) */
  293.     ushort CKS; /* ChecK recordS,nb of rec in dir (8, >16, 32) */
  294.     ushort OFS; /* OFfSet, reserved tracks (1, >2, 3, 4) */
  295.  
  296. /* extended DPB info, automatically calculated */
  297.     ushort BLS; /* BLock Size in bytes (>1024, 2048)*/
  298.     bool   SYS; /* CP/M present in system tracks */
  299.     ushort DBL; /* Directory BLocks = CKS/8 */
  300. } DPB_type;
  301.  
  302.  
  303. /* DPB templates for SYSTEM, DATA, IBM, VORTEX, and user defined */
  304. extern const int DPB_store_size;
  305. typedef enum {    SYSTEM_DPB=0,
  306.         DATA_DPB=1,
  307.         IBM_DPB=2,
  308.         VORTEX_DPB=3,
  309.         USER_DPB=4
  310. } DPB_Index_Type;
  311. extern DPB_type DPB_store[];
  312.  
  313. extern DPB_type *dpb;    /* pointer to current DPB */
  314.  
  315.  
  316.  
  317. /*******
  318.   Tools
  319.  *******/
  320.  
  321. void putcharm(int,char);
  322. void printm(int,char*,...);
  323. char *lower(char*);
  324. char *upper(char*);
  325. char *append_suffix (char*,char*);
  326. int  errorf (bool,const char*,...);
  327. const char *show_attr(int attr, int mask, bool always);
  328. const char* show_all_attr(int att, bool always);
  329. void do_break();
  330. void newpage(char* keys);
  331. char nextline();
  332. char *repstr(char c,int times);
  333. char *show_format (uchar sec_offset);
  334. char *show_mode (int m);
  335. void reparse (int argnb);
  336. void expand_percent(char *from, char *to, int max);
  337. void echom (int v, char *p);
  338. bool confirmed() ;
  339. bool tag_ok ();
  340. void alloc_block(int blk,int file);
  341. void free_block(int blk);
  342. bool is_free_block(int blk);
  343. void calc_allocation ();
  344. bool inactive ();
  345. int  trk_calc (int blk);
  346. int  sec_calc (int blk);
  347. void abandonimage();
  348. int  parse_cpm_filename(char *name, int *user, char *root, char *ext);
  349. int  parse_filename(char *name, int *drive, char *path, char *root, char *ext);
  350. int  pager(char *filename);
  351. bool has_wildcards(char os_tag, char *filename);
  352. void build_cpm_name   (char *buf, int user, char *root, char *ext);
  353. void build_cpm_name_32(char *buf, int user, char *root, char *ext);
  354. void str2mem(char *mem, char *str, int spc);
  355. char *show_hex(int nr, uchar *buf, int size);
  356. void *Malloc(int bytes);
  357.  
  358.  
  359. /********
  360.   Tracks
  361.  ********/
  362.  
  363. int  read_track (int hd, int trk);
  364. int  write_track();
  365. bool next_sector(int*,int*,int*);
  366.  
  367. /***********
  368.   Directory
  369.  ***********/
  370.  
  371. void get_directory();
  372. void put_directory();
  373. void update_directory();
  374.  
  375. extern int glob_env;
  376. int glob_cpm_next();
  377. int glob_cpm_file(char *pat);
  378.  
  379. /*******
  380.   Image
  381.  *******/
  382.  
  383. void close_image();
  384. int  open_image(char *name);
  385. int  format(char* name,DPB_type *dpb);
  386. int  sysgen(char* name);
  387. int  comment_image(const char *text);
  388.     
  389. /********
  390.   Blocks
  391.  ********/
  392.  
  393. int  get_free_block();
  394.  
  395.  
  396. /*****************
  397.   FS Maintenance
  398.  *****************/
  399.  
  400. long delete (bool silent, char *pattern) ;
  401. int  parse_attr(char *str, int *mask, bool *set);
  402. int  change_attrib(char* pattern, int set, int reset);
  403.  
  404. /**********
  405.   Transfer
  406.  **********/
  407.  
  408. int  detectmode (char *buf, int size) ;
  409. long get (char *src,char *target);
  410. long put (char *src, char *trg);
  411. int  dir(char *pat, int mask);
  412. int  ren_file(char *from, char *to);
  413. int  ren_wild(char *pat, int user);
  414. int  copy_file(char *from, char *to);
  415. int  copy_wild(char *pat, int user);
  416.  
  417. /*********
  418.   Dumping
  419.  *********/
  420.  
  421. int  dump(FILE *file, int block, int head, int track, int sector);
  422. int  dumpdir (FILE *file);
  423. int  map (FILE *file);
  424.  
  425.  
  426. /****************
  427.   User Interface
  428.  ****************/
  429.  
  430. int  execute_file (char *name);
  431. int  execute_cmd (char *cmd);
  432. /*int  execute_one_cmd (char *cmd);*/
  433.  
  434. #if DOS
  435. #define vert    0xB3
  436. #define hori    0xC4
  437. #define cross    0xC5
  438. #else
  439. #define vert    '|'
  440. #define hori    '-'
  441. #define cross    '+'
  442. #endif
  443.  
  444.  
  445. #endif
  446.